<?php

/*

PHP-MUA for Desktopd
Copyright (C) 2015  Desktopd Developer(s)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

https://www.gnu.org/licenses/agpl.html

*/


namespace Desktopd\MUA;


require_once __DIR__ . '/autoloader.php';


// coding like this would be much easier in ECMAScript or something
(new \ReflectionFunction(function () {
    $printMessage = function (Message $message, $prefix = '') use (&$printMessage) {
        try {
            $message = new MultipartMessage($message, true);
            $count = 0;
            foreach ($message as $part) {
                echo "\r\nPART #{$prefix}{$count}:\r\n", $part;
                $printMessage($part, "{$prefix}{$count}.");
                $count++;
            }
        } catch (\Exception $e) {
            echo "\r\nDecoded content:\r\n", $message->getText();
        }
    };
    
    $message = new ReceivedMessage(file_get_contents('php://stdin'));
    $printMessage($message);
    
}))->invoke();


// vim: ts=4 et ai

